<?php
namespace app\admin\module;

use app\common\model\Article;
use app\common\model\Cate;
use think\Exception;

class CateModule {

    public static function page($pageSize = 10){
        return Cate::where([])->order('id','desc')->paginate($pageSize);
    }

    public static function create($data){
        Cate::create($data);
    }

    public static function update($data){
        Cate::update($data,['id'=>$data['id']]);
    }

    public static function del($id){
        $exists = Article::where(['cate_id'=>$id])->find();
        if($exists){
            throw new Exception("有文章再使用该分类，不能删除");
        }
        Cate::destroy($id);
    }

    public static function all(){
        return Cate::select();
    }

}